﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _001_MVVM基础.Model
{
    public partial class Dog : ObservableObject
    {
        [ObservableProperty]
        private string? food;

        //[ObservableProperty]
        //private string? result;

        //[RelayCommand]
        //private void Feed()  //Feed => FeedCommand
        //{

        //}
        /// <summary>
        /// 相同方法无法通过参数多少区别，只能保留一个
        /// </summary>
        /// <param name="f"></param>
        [RelayCommand]
        private void Feed(string? f)
        {
            food = "狗粮";
            if (f != null)
            {
                Food = f;
            }
        }

        [RelayCommand]
        private async void AsyncFeed(string? f)
        {
            await Task.Run(() => { });

        }

        [ObservableProperty]
        [NotifyCanExecuteChangedFor(nameof(Feed3Command))]
        private bool feed3CanExecute;

        //[RelayCommand]
        [RelayCommand(CanExecute = nameof(Feed3CanExecute))]
        private void Feed3(string? f)
        {
            if (f != null)
            {
                Food = f;
            }
        }
    }
}
